<template>
  <div style="float: left;margin-top: 5px">
    <el-form ref="searchRef" :model="searchFormData">
      <el-form-item label="关键词" >
        <el-input  type="text" v-model="searchFormData.keyWord"></el-input>
      </el-form-item>
    </el-form>
  </div>
  <div style="height: 40px;margin-top: 5px;float: left;margin-left: 20px;">
    <el-button @click="searchClick">查询</el-button>
    <el-button  @click="extractionLog">提取日志</el-button>
  </div>
  <div style="clear: both"></div>
  <div style="height: calc(100% - 60px);">
    <Table  :show-page="true" ref="tableRef" :show-line-number="true"
            :showCheckBox="false" :url="fileUrl" :columns="columns">
      <template  v-slot:handle="slotProps">
        <el-button  @click="showEchartDialog">图表</el-button>
      </template>
    </Table>
  </div>
  <DialogForm ref="editFormRef" :form="editDialogForm" title="编辑" @validateSuccess="validateSuccess">
  </DialogForm>
  <el-dialog title="图表信息" v-model="dialogEchartVisible" :close-on-click-modal="false" >

  </el-dialog>
</template>

<script setup>

import Table from "@/components/plugs/table/Table.vue";
import DialogForm from "@/components/plugs/form/DialogForm.vue";
import {inject, reactive, ref, toRaw} from "vue";
import {FormItemType} from "@/components/plugs/form/DialogFormInterface.js";
import {AXIOS_NAME} from "@/constant/constant.js";
import {ElMessage, ElMessageBox} from "element-plus";
import {deleteRow, HandleEnum} from "@/utils/utils.ts";

const tableRef = ref(null);
const $axios = inject(AXIOS_NAME);
const searchRef = ref(null);
const editFormRef = ref(null);
const dialogEchartVisible = ref(false);
const fileUrl = ref("/file/getFilePage?businessType=2");

const searchFormData = reactive({
  'keyWord': ''
});

const columns = [
  {field:"fileName","desc": "文件名称"},
  {field:"exceptionType","desc": "异常类型"},
  {field:"uuidFileName","desc": "名称"},
  {field:"filePath","desc": "文件地址"},
  {field:"fileSize","desc": "文件大小"},
  {field:"fileLongSize","desc": "文件大小"},
  {field:"fileSuffix","desc": "后缀"},
  {field:"showTime","desc": "创建时间"}
];

let items = [];
items.push({type: FormItemType.INPUT_HIDDEN,label: 'id',name: 'id'});
let editDialogForm = reactive({
  splitCol: 1,
  gutter: 20,
  labelWidth: 115,
  items:items,
  rules:{},
});

const searchClick = () =>{
  tableRef.value.reload(toRaw(searchFormData));
}

const showEchartDialog = () => {
  dialogEchartVisible.value = true;
}

const resetSearchClick = () =>{
  for(const  key in searchFormData){
    searchFormData[key] = '';
  }
}

const extractionLog = ()=>{
  ElMessageBox.confirm(
      '是否提取日志?','提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  ).then(() => {
    $axios.post('/outerLog/gather',{}).then(response => {
      const data = response.data;
      if(data.code == 1){
        tableRef.value.reload();
        editFormRef.value.close();
        ElMessage.info("操作成功！");
        return;
      }
      ElMessage.error(data.msg);
    },error =>{

    });
  });
}

const addClick = () =>{
  editFormRef.value.show();
}

const editTableData = (rowData,rowIndex) =>{
  editFormRef.value.show();
  editFormRef.value.setData(rowData);
}

const deleteTableRowData = (rowData,rowIndex) =>{
  deleteRow('',rowData,function (state,data){
    if(state == HandleEnum.SUCCESS){
      tableRef.value.reload();
    }
  });
}

const validateSuccess = (data) =>{
  $axios.post('/outerLog/',data).then(response => {
    const data = response.data;
    if(data.code == 1){
      tableRef.value.reload();
      editFormRef.value.close();
      ElMessage.info("操作成功！");
      return;
    }
    ElMessage.error(data.msg);
  },error =>{

  });
}
</script>

<style scoped>

</style>